/*
 * Email field validator
 *  
 * Copyright (C) 2011 Antti Leppä / Otavan Opisto
 * http://www.otavanopisto.fi
 * 
 * License: 
 * 
 * Licensed under GNU Lesser General Public License Version 3 or later (the "LGPL") 
 * http://www.gnu.org/licenses/lgpl.html
 */
fi.internetix.validation.validator.EmailFieldValidator = Class.create(fi.internetix.validation.FieldValidator, 
  /** @lends fi.internetix.validation.validator.EmailFieldValidator# **/   
  {
  /**
  * Class constructor
  * @class Constructs this class
  * @extends fi.internetix.validation.FieldValidator
  * @constructs
  * @param $super super class 
  */
  initialize : function($super) {
    $super();
    this._validEmailMask = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  },
  validate: function ($super, field) {
    var value = this._getFieldValue(field);
    
    if (value) {
      return this._validEmailMask.test(value.strip()) ? fi.internetix.validation.FieldValidator.STATUS_VALID : fi.internetix.validation.FieldValidator.STATUS_INVALID;
    } else {
      return fi.internetix.validation.FieldValidator.STATUS_UNKNOWN;
    }
  },
  getType: function ($super) {
    return fi.internetix.validation.FieldValidator.TYPE_NORMAL;
  },
  getClassName: function () {
    return 'email';
  }
});

fi.internetix.validation.FieldValidatorVault.registerValidator(new fi.internetix.validation.validator.EmailFieldValidator());